<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="patientPhone">
        <el-input
          v-model="queryParams.patientPhone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="patientIdcard">
        <el-input
          v-model="queryParams.patientIdcard"
          placeholder="请输入身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          :disabled="single"
          @click="handleAdd"
          v-hasPermi="['outpatient:library:query']"
        >查看档案</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['outpatient:library:Casequery']"
        >查看就诊病例</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="patientName" />
      <el-table-column label="电话" align="center" prop="patientPhone" />
      <el-table-column label="身份证号" align="center" prop="patientIdcard" />
      <el-table-column label="出生年月" align="center" prop="patientBirth" />
      <el-table-column label="年龄" align="center" prop="patientAge" />
      <el-table-column label="性别" align="center" prop="patientSex" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="openInfo" width="70%" center append-to-body>
    <el-form label-position="left" label-width="100%" inline class="demo-table-expand">
       <el-form-item label="患者id：" prop="patientId" >
         <span v-text="form.patientId"  />
       </el-form-item>
       <el-form-item label="患者姓名：" prop="patientName">
         <span v-text="form.patientName" />
       </el-form-item>
       <el-form-item label="患者科室：" prop="patientDept">
         <span v-text="form.patientDept"  />
       </el-form-item>
        <el-form-item label="患者性别：" prop="patientSex">
          <span v-text="form.patientSex"  />
       </el-form-item>
        <el-form-item label="患者身份证：" prop="patientIdcard">
          <span v-text="form.patientIdcard"  />
       </el-form-item>
         <el-form-item label="患者年龄：" prop="patientAge">
           <span v-text="form.patientAge"  />
       </el-form-item>
        <el-form-item label="患者电话：" prop="patientPhone">
          <span v-text="form.patientPhone"  />
       </el-form-item>
        <el-form-item label="患者地址：" prop="patientAddr">
          <span v-text="form.patientAddr"  />
       </el-form-item>
        <el-form-item label="患者出生日期：" prop="patientBirth">
          <span v-text="form.patientBirth"  />
       </el-form-item>
         <el-form-item label="患者过敏史：" prop="patientAlle">
           <span v-text="form.patientAlle"  />
       </el-form-item>
         <el-form-item label="创建者：" prop="createBy">
           <span v-text="form.createBy"  />
       </el-form-item>
         <el-form-item label="创建时间：" prop="createTime">
           <span v-text="form.createTime"  />
       </el-form-item>
         <el-form-item label="更新者：" prop="updateBy">
           <span v-text="form.updateBy"  />
       </el-form-item>
         <el-form-item label="更新时间：" prop="updateTime">
           <span v-text="form.updateTime"  />
       </el-form-item>
       <el-form-item label="备注：" prop="remark">
         <span v-text="form.remark"  />
       </el-form-item>
     </el-form>

    </el-dialog>
    <el-dialog :title="title" :visible.sync="openCase" width="70%" center append-to-body>
      <el-form label-position="left" label-width="100%" inline class="demo-table-expand">
        <el-form-item  label="病例id：" prop="caseId" >
          <span v-text="form.caseId"  />
        </el-form-item>
        <el-form-item label="患者id：" prop="patientId" >
          <span v-text="form.patientId"  />
        </el-form-item>
        <el-form-item label="发病日期：" prop="illnessDate">
          <span v-text="form.illnessDate" />
        </el-form-item>
        <el-form-item label="接诊类型：" prop="receptionType">
          <span v-text="form.receptionType"  />
        </el-form-item>
        <el-form-item label="是否传染：" prop="isInfect">
          <span v-text="form.isInfect"  />
        </el-form-item>
        <el-form-item label="患者自述：" prop="chiefComplaint">
          <span v-text="form.chiefComplaint"  />
        </el-form-item>
        <el-form-item label="诊断信息：" prop="diagnose">
          <span v-text="form.diagnose"  />
        </el-form-item>
        <el-form-item label="医生建议：" prop="advise">
          <span v-text="form.advise"  />
        </el-form-item>
        <el-form-item label="医生备注：" prop="doctorNotes">
          <span v-text="form.doctorNotes"  />
        </el-form-item>
        <el-form-item label="创建者：" prop="createBy">
          <span v-text="form.createBy"  />
        </el-form-item>
        <el-form-item label="创建时间：" prop="createTime">
          <span v-text="form.createTime"  />
        </el-form-item>
        <el-form-item label="更新者：" prop="updateBy">
          <span v-text="form.updateBy"  />
        </el-form-item>
        <el-form-item label="更新时间：" prop="updateTime">
          <span v-text="form.updateTime"  />
        </el-form-item>
        <el-form-item label="备注：" prop="remark">
          <span v-text="form.remark"  />
        </el-form-item>
      </el-form>



      <!--        <el-table-column label="患者id" align="center" prop="patientId" />
              <el-table-column label="患者姓名" align="center" prop="patientName" />
              <el-table-column label="患者科室" align="center" prop="patientDept" />
              <el-table-column label="患者性别" align="center" prop="patientSex" />
              <el-table-column label="患者身份证" align="center" prop="patientIdcard" />
              <el-table-column label="患者年龄" align="center" prop="patientAge" />
              <el-table-column label="患者电话" align="center" prop="patientPhone" />
              <el-table-column label="患者地址" align="center" prop="patientAddr" />
              <el-table-column label="患者出生日期" align="center" prop="patientBirth" />
              <el-table-column label="患者过敏史" align="center" prop="patientAlle" />
              <el-table-column label="创建者" align="center" prop="createBy" />
              <el-table-column label="创建时间" align="center" prop="createTime" />
              <el-table-column label="更新者" align="center" prop="updateBy" />
              <el-table-column label="更新时间" align="center" prop="updateTime" width="180"/>
              <el-table-column label="备注" align="center" prop="remark" width="180"/>-->
<!--      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>-->
    </el-dialog>
  </div>
</template>

<script>
import {listPost, getPost, delPost, addPost, updatePost, exportPost, getCase} from "@/api/outpatient/post";

export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否查看档案弹出层
      openInfo: false,
      //是否现实查看病例弹出层
      openCase: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" }
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" }
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询患者列表 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.patientId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 查看档案按钮操作 */
    handleAdd(row) {
      this.reset();
      const postId = row.patientId || this.ids
      getPost(postId).then(response => {
        this.form = response.data;
        this.openInfo = true;
        this.title = "查看档案";
      });
    },

    /** 查看就诊病例按钮操作 */
    handleUpdate(row) {
      this.reset();
      const  postId = row.patientId || this.ids
      getCase( postId).then(response => {
        this.form = response.data;
        this.openCase = true;
        this.title = "查看就诊病例";
      });
    },

  }
};
</script>
